import express from 'express';
import session from 'express-session';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import morgan from 'morgan';
import routes from './app/routes.js';
const app = express();
/** 项目启动端口 */
const port = 3307;

import flash from 'connect-flash';

/** 数据库连接 */
import { init } from './config/sqlControl.js';
init();

app.use(morgan('dev'));
app.use(cookieParser());
/** 处理post请求body参数数据 */
app.use(bodyParser.urlencoded({
	extended: true
}));
app.use(bodyParser.json());

app.set('view engine', 'ejs'); // set up ejs for templating

/** session */
app.use(session({
	secret: 'vidyapathaisalwaysrunning',
	resave: true,
	saveUninitialized: true
}));
app.use(flash());

routes(app);
app.listen(port);
console.log('carRental run port ' + port);
